ApplicationLogin = function(){
	var url = '${request.contextPath}/auth/checkuser.action';
	
	var usernameValue = $('username').get('value'); 
	var passwordValue = $('password').get('value'); 
	
	if (usernameValue == '' || passwordValue ==''){
		MUI.notification('用户名或口令不能为空！');
		return;
	}
	
	$('btnlogin').innerHTML='<img src="${request.contextPath}/resources/images/spinner.gif" width="16px" height="16px">';
	
	var request = new Request.JSON({
		url: url,
		onComplete: function(json,text) {
			//alert(text);
			if (json.login==1){
			   //alert('login success');
			   window.location.href='desktop.action';
			}else{
			   $('btnlogin').innerHTML='<input name="blogin" id="blogin" type="button" class="submit" value="" />';
			   MUI.notification('用户名或口令错误，请重新输入！');
			}
		}
	}).get({"username":usernameValue,"password":passwordValue});
}

var enterEvent = function(event){ 
    // 下面的代码是说： 
    // 如果按下的键为“enter”，则做下面的事 
    if (event.key == 'enter') {  
        ApplicationLogin();
    }
} 

initializeColumns = function() {
	if ($('desktop')){
		$('desktop').addEvent('keydown', function(e) {
			//new Event(e).stop();
			enterEvent(e);
		});
	}

	var loginhtml = '<div align="center">';
	loginhtml += '<form name="form1" autocomplete="off" onsubmit="return false;">';
	//loginhtml += '<div class="login_div" align="center">';
	loginhtml += '<table border="0" width="400px" height="300px"><tr>';
	loginhtml += '<td>用户名</td><td><input id="username" type="text" class="text" name="username" maxlength="20" onmouseover="this.focus()" onfocus="this.select()" value="" /></td>';
	loginhtml += '<td>密码</td><td><input id="password" type="password" class="text" name="password" onmouseover="this.focus()" onfocus="this.select()" value="" /></td>';
	loginhtml += '<td width="78px" height="28px"><div id="btnlogin"><input name="blogin" id="blogin" type="button" class="submit" value="" /></div></td></tr></table>';
	loginhtml += '</div>';
	
	new MUI.Column({
		id: 'mainColumn',
		placement: 'main',
		resizeLimit: [100, 300]
	});

	// Add panels to main column	
	new MUI.Panel({
		id: 'mainPanel',
		title: '登录',
		content: loginhtml,
		column: 'mainColumn'
	});

	MUI.myChain.callChain();
	
	if ($('blogin')){
		$('blogin').addEvent('click', function(e) {
			new Event(e).stop();
			ApplicationLogin();
		});
	}
}

// Initialize MochaUI when the DOM is ready
window.addEvent('load', function(){ //using load instead of domready for IE8

	MUI.myChain = new Chain();
	MUI.myChain.chain(
		function(){MUI.Desktop.initialize();},
		function(){MUI.Dock.initialize();},
		function(){initializeColumns();}	
	).callChain();	

});
